# coding: utf-8
"""
@version: python3.6
@author: 噢啦嘿嘿
@contact: jian.zhou@360che.com
@software: PyCharm
@file: home.py
@time: 2021/1/21 15:56
"""

from public.App_Page import AppPage, BasePage
from lib.loggers import log
import time
from lib.func import think_time


class Home(BasePage):


    @think_time
    def gohome(self):
        while not self.find_text("尿素加注"):
            self.d.press("back")
            if self.find_text("首页"):
                if self.find_text("推荐"):
                    self.find_text("推荐").click()
                self.find_text("首页").click()
            time.sleep(0.3)

    @think_time
    def go社区(self):
        self.find_text("论坛").click()
        
    @think_time
    def go招聘(self):
        self.find_text("司机招聘").click()

    @think_time
    def go问答(self):
        self.find_text("求助问答").click()

    @think_time
    def textclick(self, text):
        self.find_text(text).click()

    def go尿素(self):
        self.find_text("尿素加注").click()

    @think_time
    def click发帖(self):
        self.find_id('com.truckhome.bbs:id/iv_community_main_post').click()

    @think_time
    def click帖子(self):
        self.find_text("帖子").click()

    @think_time
    def input标题(self, text):
        self.input_text(self.find_id("com.truckhome.bbs:id/edit_title"), text)

    @think_time
    def input内容(self, text):
        self.input_text(self.find_text("分享精彩正能量的内容将有助于管理员加精"), text)

    @think_time
    def swipe_L(self, content):
        """从UI对象的中心滑动到UI对象的左边缘"""
        self.d.xpath(content).swipe("left")


    @think_time
    def huaDongChaZhao(self,):
        '''滑动整屏'''
        self.d(scrollable=True).fling()

    @think_time
    def text_click(self, text):
        '''
        text 点击
        :param text: 文本
        :return:
        '''
        self.find_text(text).click()


    @think_time
    def id_click(self, id):
        '''
        resourceId 点击
        :param id:
        :return:
        '''
        self.find_id(id).click()

    @think_time
    def find_text(self, ele):
        return self.d(text = ele)


    @think_time
    def get_title(self, id):
        # 根据文本查找id
        return self.gettitle_text(self.find_id(id))

    @think_time
    def get_window(self,text):
        # 根据文本查找文本
        return self.gettitle_text(self.find_text(text))

    @think_time
    def get_text(self, text):
        # 根据文本查找文本
        return self.gettitle_text(self.find_text(text))

    @think_time
    def get_id(self, id):
        # 根据xpath查找id
        return self.find_xpath(self.find_id(id))

    # @think_time
    # def sliding(self):
    #     '''向上滑动整屏'''
    #     self.d(scrollable=True).fling()
    @think_time
    def scrollable_one(self):
        '''滑动整屏'''
        self.d(scrollable=True).fling()

    @think_time
    def scrollable_up(self):
        '''
        向上滑动
        :return:
        '''
        self.d.swipe_ext("up")

    @think_time
    def scrollable_down(self):
        '''向下滑动到顶部'''
        try:
            self.d.swipe_ext("down")
            time.sleep(1)
        except:
            raise
        finally:
            time.sleep(1)

    @think_time
    def scrollable_description(self, position):
        '''
        根据文本滑动找到某个特定元素
        :param position:
        :return:
        '''
        self.d(scrollable=True).scroll.to(text=position)

        #self.d(scrollable=True).scroll.horiz.to(text=position)
        #self.d(scrollable=True).scroll.forward.to(text=position)

        # 去我的页面

    @think_time
    def go_mypage(self):
        self.find_text("我的").click()
        while not self.find_text("我的"):
            # self.back()
            if self.find_text("我的"):
                self.back()
            time.sleep(0.5)

    # 滑动一屏到最左侧
    @think_time
    def get_scorll_right(self):
        self.d(scrollable=True).scroll.horiz.toBeginning()

